<template>
    <el-select v-model="currentLanguage" @change="changeLanguage" placeholder="Select language" class="e-select">
        <el-option label="中文" value="zh"></el-option>
        <el-option label="English" value="en"></el-option>
    </el-select>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { useI18n } from 'vue-i18n'

// 获取 i18n 实例
const { locale } = useI18n()

// 从 localStorage 中获取当前语言，默认为 'zh'
const savedLanguage = localStorage.getItem('language') || 'zh'
const currentLanguage = ref(savedLanguage)

const changeLanguage = (language) => {
    locale.value = language  // 修改语言
    localStorage.setItem('language', language)  // 将选择的语言保存到 localStorage
}

// 页面加载时设置语言
onMounted(() => {
    locale.value = savedLanguage
})
</script>

<style scoped>
</style>
